package leetcode.templates.twos;

import java.util.Arrays;

public class MaxTwo1 {

	int mod = 1000000007;
	// 双针不回退
	public int purchasePlans(int[] nums, int target) {
		Arrays.sort(nums);
		int len = nums.length;
		long ans = 0;
		for (int i = 0, j = len - 1; i < len && i < j; i++) {
			int cur = nums[i], find = target - cur;
			while (j > i && nums[j] > find) {
				j--;
			}
			ans += j - i;
			ans %= mod;
		}
		return (int) ans;
	}

}
